package com.wzz.seckillone.controller;

import com.alibaba.fastjson.JSON;
import com.wzz.seckillone.common.AjaxResult;
import com.wzz.seckillone.pojo.User;
import com.wzz.seckillone.service.SeckillOrderService;
import com.wzz.seckillone.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private UserService userService;

    @Autowired
    private SeckillOrderService seckillOrderService;

    @GetMapping("/toDetails")
    public String toDetails(Model model){
        model.addAttribute("orderId","8193434217209225216");
        return "orderDetailPlus";
    }

    @GetMapping("/detail")
    @ResponseBody
    public String getDetail(String orderId){
        AjaxResult result = new AjaxResult();
        try{
            result.setSuccess(true).setData(seckillOrderService.getOrderDetailsByOrderId(orderId));
        }catch (Exception e){
            result.setSuccess(false).setMessage("查询失败");
        }
        return JSON.toJSONString(result);
    }


    @GetMapping("/hello")
    public String hello(Model model){
        model.addAttribute("msg","你好");
        return "hello";
    }

    @GetMapping("/mapper")
    @ResponseBody
    public User getMapper(String id){
        return userService.test(id);
    }
}
